package com.tgy.recursion;

/**
 * @Author: tgy
 * @Date: 2020-10-30 09:32
 */
public class Hanoi {

    public void hanoi(int n) {

        hanoi(n,"P1","P2","P3");
    }

    /**
     * 把n个盘子从p1移动到p3
     * @param n
     * @param p1
     * @param p2
     * @param p3
     */
    private void hanoi(int n,String p1,String p2, String p3) {

        if (n == 1) {

            move(n,p1,p3);
            return;
        }

        hanoi(n-1,p1,p3,p2);
        move(n,p1,p3);
        hanoi(n-1,p2,p1,p3);
    }

    public void move(int n,String p1,String p2) {

        System.out.println(n + "从" + p1 + "移动到" + p2);
    }

}
